#include <QFileDialog>
#include "matchcontrol.h"

using namespace PBVP;

MatchControl::MatchControl(FileExtensionManager *pFileExtManager, QWidget *parent)
	: QDialog(parent)
{
	m_pFileExtManager = pFileExtManager;
	ui.setupUi(this);

	connect(ui.volButton1, SIGNAL(pressed()), this, SLOT(setVolumeFile1()));
	connect(ui.volButton2, SIGNAL(pressed()), this, SLOT(setVolumeFile2()));
	connect(ui.dctButton1, SIGNAL(pressed()), this, SLOT(setDCTFile1()));
	connect(ui.dctButton2, SIGNAL(pressed()), this, SLOT(setDCTFile2()));
	connect(ui.volFileName1, SIGNAL(textChanged(const QString&)), this, SLOT(updateDCTPath1(const QString&)));
	connect(ui.volFileName2, SIGNAL(textChanged(const QString&)), this, SLOT(updateDCTPath2(const QString&)));
}

MatchControl::~MatchControl()
{

}

void MatchControl::getWeights(double wts[4])
{
	wts[0] = ui.geometryWt->text().toDouble();
	wts[1] = ui.shapeWt->text().toDouble();
	wts[2] = ui.topologyWt->text().toDouble();
	wts[3] = ui.propertyWt->text().toDouble();
}

//////////////////////////////////////////////////////////////////////////
// Slots
//////////////////////////////////////////////////////////////////////////
void MatchControl::updateDCTPath1(const QString &path)
{
	QString dctPath(path);
	ui.dctFileName1->setText(dctPath.append(".dct"));
}

void MatchControl::updateDCTPath2(const QString &path)
{
	QString dctPath(path);
	ui.dctFileName2->setText(dctPath.append(".dct"));
}

void MatchControl::setVolumeFile1()
{
	QString fname = QFileDialog::getOpenFileName(this, "Open Volume File 1", "", 
		m_pFileExtManager->filter(VOLUME_DATA));	
	if (!fname.isNull()) {
		ui.volFileName1->setText(fname);
	}
}

void MatchControl::setVolumeFile2()
{
	QString fname = QFileDialog::getOpenFileName(this, "Open Volume File 2", "", 
		m_pFileExtManager->filter(VOLUME_DATA));	
	if (!fname.isNull()) {
		ui.volFileName2->setText(fname);
	}
}

void MatchControl::setDCTFile1()
{
	QString fname = QFileDialog::getOpenFileName(this, "Open DCT File 1", "", 
		"DCT Files(*.dct);;All Files(*.*)");
	if (!fname.isNull())
	{
		ui.dctFileName1->setText(fname);
	}
}

void MatchControl::setDCTFile2()
{
	QString fname = QFileDialog::getOpenFileName(this, "Open DCT File 2", "", 
		"DCT Files(*.dct);;All Files(*.*)");
	if (!fname.isNull())
	{
		ui.dctFileName2->setText(fname);
	}
}